<?php
namespace Controllers;
class CommonController {
    // home/index
    public function render($tpl, $data = []) {
        $filePath = './Views/' . $tpl . '.php';
        extract($data); // $msg = 'Git地址：https://gitee.com/yiibook/21mvc'
        if (!file_exists($filePath)) {
            echo '视图' . $tpl . '不存在'; exit;
        }
        include_once $filePath;
    }

    public function responseJson($code, $msg, $data = []) {
        return json_encode(compact('code', 'msg', 'data'));
    }
}